home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / actionrp / nhplusx.bin / nhplusx / nhplusX / X11 / winval.c < prev    next >
C/C++ Source or Header  |  1995-09-10  |  4KB  |  171 lines

  1. /*    SCCS Id: @(#)winval.c    3.1    92/3/7
  2. /* Copyright (c) Dean Luick, 1992                  */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /*
  6.  * Routines that define a name-value label widget pair that fit inside a
  7.  * form widget.
  8.  */
  9. #include <stdio.h>
  10.  
  11. #ifndef SYSV
  12. #define PRESERVE_NO_SYSV    /* X11 include files may define SYSV */
  13. #endif
  14.  
  15. #include <X11/Intrinsic.h>
  16. #include <X11/StringDefs.h>
  17. #include <X11/Xaw/Label.h>
  18. #include <X11/Xaw/Form.h>
  19. #include <X11/Xaw/Cardinals.h>
  20.  
  21. #ifdef PRESERVE_NO_SYSV
  22. # ifdef SYSV
  23. #  undef SYSV
  24. # endif
  25. # undef PRESERVE_NO_SYSV
  26. #endif
  27.  
  28. #include "config.h"    /* #define for const for non __STDC__ compilers */
  29.  
  30. #define NAME "name"
  31. #define VALUE "value"
  32.  
  33.  
  34. Widget
  35. create_value(parent, name_value)
  36.     Widget parent;
  37.     const char *name_value;
  38. {
  39.     Widget form, name;
  40.     Arg args[8];
  41.     Cardinal num_args;
  42.  
  43.     num_args = 0;
  44.     XtSetArg(args[num_args], XtNborderWidth, 0);        num_args++;
  45.     XtSetArg(args[num_args], XtNdefaultDistance, 0);        num_args++;
  46.     form = XtCreateManagedWidget(name_value,
  47.                 formWidgetClass,
  48.                 parent, args, num_args);
  49.  
  50.     num_args = 0;
  51.     XtSetArg(args[num_args], XtNjustify, XtJustifyRight);    num_args++;
  52.     XtSetArg(args[num_args], XtNborderWidth, 0);        num_args++;
  53.     XtSetArg(args[num_args], XtNlabel, name_value);        num_args++;
  54.     XtSetArg(args[num_args], XtNinternalHeight, 0);        num_args++;
  55.     name = XtCreateManagedWidget(NAME,
  56.                 labelWidgetClass,
  57.                 form, args, num_args);
  58.  
  59.     num_args = 0;
  60.     XtSetArg(args[num_args], XtNjustify, XtJustifyRight);    num_args++;
  61.     XtSetArg(args[num_args], XtNborderWidth, 0);        num_args++;
  62.     XtSetArg(args[num_args], XtNfromHoriz, name);        num_args++;
  63.     XtSetArg(args[num_args], XtNinternalHeight, 0);        num_args++;
  64.     (void) XtCreateManagedWidget(VALUE,
  65.                 labelWidgetClass,
  66.                 form, args, num_args);
  67.     return form;
  68. }
  69.  
  70. void
  71. set_name(w, new_label)
  72.     Widget w;
  73.     char *new_label;
  74. {
  75.     Arg args[1];
  76.     Widget name;
  77.  
  78.     name = XtNameToWidget(w, NAME);
  79.     XtSetArg(args[0], XtNlabel, new_label);
  80.     XtSetValues(name, args, ONE);
  81. }
  82.  
  83. void
  84. set_name_width(w, new_width)
  85.     Widget w;
  86.     int new_width;
  87. {
  88.     Arg args[1];
  89.     Widget name;
  90.  
  91.     name = XtNameToWidget(w, NAME);
  92.     XtSetArg(args[0], XtNwidth, new_width);
  93.     XtSetValues(name, args, ONE);
  94. }
  95.  
  96. int
  97. get_name_width(w)
  98.     Widget w;
  99. {
  100.     Arg args[1];
  101.     Dimension width;
  102.     Widget name;
  103.  
  104.     name = XtNameToWidget(w, NAME);
  105.     XtSetArg(args[0], XtNwidth, &width);
  106.     XtGetValues(name, args, ONE);
  107.     return (int) width;
  108. }
  109.  
  110.  
  111. void
  112. set_value(w, new_value)
  113.     Widget w;
  114.     const char *new_value;
  115. {
  116.     Arg args[1];
  117.     Widget val;
  118.     
  119.     val = XtNameToWidget(w, VALUE);
  120.     XtSetArg(args[0], XtNlabel, new_value);
  121.     XtSetValues(val, args, ONE);
  122. }
  123.  
  124. void
  125. set_value_width(w, new_width)
  126.     Widget w;
  127.     int new_width;
  128. {
  129.     Arg args[1];
  130.     Widget val;
  131.     
  132.     val = XtNameToWidget(w, VALUE);
  133.     XtSetArg(args[0], XtNwidth, new_width);
  134.     XtSetValues(val, args, ONE);
  135. }
  136.  
  137. int
  138. get_value_width(w)
  139.     Widget w;
  140. {
  141.     Arg args[1];
  142.     Widget val;
  143.     Dimension width;
  144.  
  145.     val = XtNameToWidget(w, VALUE);
  146.     XtSetArg(args[0], XtNwidth, &width);
  147.     XtGetValues(val, args, ONE);
  148.     return (int) width;
  149. }
  150.  
  151. /* Swap foreground and background colors (this is the best I can do with */
  152. /* a label widget, unless I can get some init hook in there).         */
  153. void
  154. hilight_value(w)
  155.     Widget w;
  156. {
  157.     Arg args[2];
  158.     Widget val;
  159.     Pixel fg, bg;
  160.  
  161.     val = XtNameToWidget(w, VALUE);
  162.     XtSetArg(args[0], XtNforeground, &fg);
  163.     XtSetArg(args[1], XtNbackground, &bg);
  164.     XtGetValues(val, args, TWO);
  165.  
  166.     XtSetArg(args[0], XtNforeground, bg);
  167.     XtSetArg(args[1], XtNbackground, fg);
  168.     XtSetValues(val, args, TWO);
  169. }
  170.  
  171.